package cn.classTest.mall.controller;

import cn.classTest.mall.domain.Department;
import cn.classTest.mall.query.QueryObject;
import cn.classTest.mall.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @RequiresPermissions(value = {"department:list", "部门列表"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, QueryObject qo) {
        PageInfo<Department> query = departmentService.query(qo);
        model.addAttribute("pageInfo", query);
        return "department/list";
    }

    @RequiresPermissions(value = {"mall:saveOrUpdate", "部门新增或编辑"}, logical = Logical.OR)
    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Department department) {
        departmentService.saveOrUpdate(department);
        return "redirect:/department/list";
    }
}
